package com.shigu.admin.manager.common;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.shigu.admin.manager.responses.SimpleResponse;

/**
 * json 返回对象
 * Created by bugzy on 2017/5/4 0004.
 */
public class JSONResult extends SimpleResponse {

    /**
     * 状态成功
     */
    public static final String SUCCESS = "success";
    /**
     * 状态失败
     */
    public static final String ERROR = "error";

    private Object data;

    public JSONResult() {
        super(ERROR);
    }

    public JSONResult(String msg) {
        this();
        this.msg = msg;
    }

    public JSONResult(String result, String msg, Object data) {
        this.result = result;
        this.msg = msg;
        this.data = data;
    }

    public String getResult() {
        return result;
    }

    public JSONResult setResult(String result) {
        this.result = result;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public JSONResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Object getData() {
        return data;
    }

    public JSONResult setData(Object data) {
        this.data = data;
        return this;
    }

    public static JSONResult success() {
        return success(null);
    }
    public static JSONResult success(String msg) {
        return success(msg, null);
    }
    public static JSONResult success(String msg, Object object) {
        return new JSONResult(SUCCESS, msg, object);
    }

    public static JSONResult error() {
        return error(null);
    }
    public static JSONResult error(String msg) {
        return new JSONResult(msg);
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this, SerializerFeature.PrettyFormat);
    }
}
